#include <iostream>
#include <cstring>
#include <queue>
#include <map>
#include <vector>
#include <string.h>
#include <algorithm>
using namespace std;

int n;
int ans = 0;
struct stick
{
    int l;
    int w;
} s[5010];

int dp[5010];

bool cmp(const stick &A, const stick &B)
{
    if (A.l > B.l)
        return true;
    else if (A.l == B.l)
        return A.w > B.w;
    return false;
}

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> s[i].l >> s[i].w;
    }

    sort(s + 1, s + 1 + n, cmp);

    for (int i = 1; i <= n; i++)
    {

    } //寻找之后小于当前数的个数,若无则说明之后没有比它小的，必须延时

    for (int i = 1; i <= n; i++)
    {
        for (int j = i - 1; j > 0; j--)
        {
            if (s[i].w > s[j].w)
                dp[i] = max(dp[i], dp[j] + 1);
        }
        ans = max(ans,dp[i]);
    }
    cout << ans +1 << endl;
    system("pause");
    return 0;
}